package com.park.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.park.entity.Park;
import com.park.entity.User;
import com.park.mapper.UserMapper;
import com.park.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    //分页查询
    public Page<User> selectPage(int current) {
        Page<User> page = new Page<>(current, 6);
        return userMapper.selectPage(page, null);

    }

    //根据手机号模糊查询
    @Override
    public List<User> getByUserCarId (String carId,int current){
        int start=current*6-6;
        int end=current*6;
        return baseMapper.getByUserCarId(carId,start,end);
    }

    //模糊查询总数
    @Override
    public int getPage(String carId) {
        return baseMapper.getPage(carId);
    }

    //删除用户
    public int delUser(int userId){
        int result=userMapper.deleteById(userId);
        return result;
    }

    //新增用户
    public int addUser(User user){
        int result=userMapper.insert(user);
        return result;
    }

    //修改用户
    public int updUser(User user){
        int result=userMapper.updateById(user);
        return result;
    }

    //根据手机号查询
    public User selectByPhone(String userPhone){
        return baseMapper.selectByPone(userPhone);

    }

}
